from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
from selenium.webdriver.common.by import By

# 实例化浏览器驱动，自动解决浏览器依赖
driver = webdriver.Chrome(ChromeDriverManager().install())
# 浏览器最大化
driver.maximize_window()
# 打开网易见外工作台
driver.get("https://jianwai.youdao.com/")
time.sleep(2)

# 登录存在多表单，我需要先切换进入表单，再定位账号、密码输入框
# 定位表单
frame_ele = driver.find_element(By.CSS_SELECTOR, "iframe[id]")
# 切换进入表单
# driver.switch_to_frame(frame_ele)  # 虽然会有waring警告，但是运行正常
driver.switch_to.frame(frame_ele)

# 定位邮箱输入框元素
email_input_ele = driver.find_element(By.CSS_SELECTOR, "input[name=email]")
# 输入邮箱
email_input_ele.send_keys("974381044@qq.com")
# 定位密码输入框
pwd_input_ele = driver.find_element(By.CSS_SELECTOR, "input[name=password]")
# 输入密码
pwd_input_ele.send_keys("zytc@12310120")
# 定位登录按钮
login_button_ele = driver.find_element(By.ID, "dologin")
# 点击-登录按钮
login_button_ele.click()

time.sleep(5)
# driver.quit()